/*
 *  Copyright (C) 2011 JiangHongTiao <jjurco.sk_gmail.com>
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package sk.lieskove301.jianghongtiao.liaad.prisoner.memory;

import java.util.Deque;
import sk.lieskove301.jianghongtiao.liaad.prisoner.strategy.FightResultEnum;

/**
 * Agent look for the last betray and count the cooperation based on this by
 * equation (1/2)^m where m is the number of days from the last betray
 * @author xjuraj
 */
public class JustForgetting extends AbstractForgetting implements Forgetting {

    private double OFI = 0.5;

    /**
     * <h4>Optimal Forgetting Index (OFI)</h4>
     * How do I remember the Fact? I have to remind myself of it before I forget.
     * Using the implemented definition of RET, one can say: I will remind myself
     * of the fact before its RET drops under a certain level. Let’s call the RET
     * volume we admit to losing the Optimal Forgetting Index (OFI). Knowing the
     * dependency of the RET on time, I can calculate from the appropriate OFI the
     * next time I need to repeat the Fact This is the basic idea for the generalization
     * of the simple advice “review after 1, 2, 4… days”.
     *
     * Example: Lets determine OFI=88%. (Therefore we admit the RET decrease to 12%).
     * Then the figure shows that the Fact must be repeated after approx. 3 days.
     * It means, agent will remember betray/cooperation from last 3 days
     * How much will our model improve by implementing the forgetting curve?
     * If we only work with the rule “repeat in 2n days” and the user does not
     * take our advice and reviews later, we can not deduct anything from
     * monitoring the results.
     * If the student in the example from the figure repeats the Fact after thirty
     * days instead of the recommended 16, we can, according to the new method,
     * still compare the expected Retrievability (deducted from the chart) and
     * the Retrievability (deducted from the points the student gets). From here,
     * we can see how much our estimate of the curve shape was correct, and
     * eventually adjust the next repetition according to this.
     * 
     * @param OFI index of forgetting
     */
    public JustForgetting(double OFI) {
        this.OFI = OFI;
    }

    public JustForgetting() {
    }

    public FightResultEnum countBetrayMemories(Deque<FightResultEnum> memory) {
        boolean my = Math.pow(0.5, countLastBetray(memory, true, 0)) < 1 - OFI;
        boolean him = Math.pow(0.5, countLastBetray(memory, false, 0)) < 1 - OFI;
        return countByResults(my, him);
    }

    public FightResultEnum countCooperateMemories(Deque<FightResultEnum> memory) {
        boolean my = Math.pow(0.5, countLastCooperation(memory, true, 0)) < 1 - OFI;
        boolean him = Math.pow(0.5, countLastCooperation(memory, false, 0)) < 1 - OFI;
        return countByResults(my, him);
    }

    public String getName() {
        return "JustForgetting";
    }

    public String getLetter() {
        return "J";
    }
    
}
